const fs = require('fs')
const { v4: uuidv4 } = require('uuid');
import { connection } from '../my_sql.js/index'


function lgh(router) {
    router.get('/abc', ctx => {
        ctx.body = 'comeDeWei'
    })


    router.get('/comeDeWei', ctx => {
        ctx.body = 'ABC'
    })


    //发布文章
    router.post('/publishtuwen', async ctx => {
        try {
            let new_p_id = new Date().getTime()
            let a = ctx.request.body.app
            let { new_p_tittle } = ctx.request.body
            let { new_p_content } = ctx.request.body
            let { new_p_label } = ctx.request.body
            let { new_is_caogao } = ctx.request.body
            let new_time = new Date().getTime()
            let new_u_id = new Date().getTime()

            ctx.body = await new Promise(function (resolve, reject) {
                let mysql = "insert into t_products_text( product_id , product_tittle , product_content , product_label , is_caogao , time , user_id ) values ( '" + new_p_id + "' , '" + new_p_tittle + "' , '" + new_p_content + "' , '" + new_p_label + "','" + new_is_caogao + "','" + new_time + "' ,'" + new_u_id + "')  "
                connection.query(mysql, function (error, results, fields) {
                    if (error) {
                        reject(error)
                    } else {
                        resolve({
                            code: 1,
                            msg: '发布成功'
                        })
                    }
                });
            })
        } catch (error) {
            console.log(error)
        }

    })
}

export {
    lgh
}